//
//  FRPCell.m
//  FunctionalReactivePixels
//
//  Created by sun on 15/7/3.
//  Copyright (c) 2015年 sunfei. All rights reserved.
//

#import "FRPCell.h"
#import "General.h"

@interface FRPCell ()

//@property (nonatomic, strong) RACDisposable *subscription;
@property (nonatomic, weak) UIImageView *imageView;

@end

@implementation FRPCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor darkGrayColor];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:imageView];
        self.imageView = imageView;
        
        RAC(self.imageView, image) = [[RACObserve(self, photoModel.thumbnailData) ignore:nil] map:^id(NSData *data) {
            return [UIImage imageWithData:data];
        }];
    }
    return self;
}

//- (void)setPhotoModel:(FRPPhotoModel *)photoModel {
//    self.subscription = [[[RACObserve(photoModel, thumbnailData) filter:^BOOL(id value) {
//        return value != nil;
//    }] map:^id(id value) {
//        return [UIImage imageWithData:value];
//    }] setKeyPath:@keypath(self.imageView, image) onObject:self.imageView];
//}

- (void)prepareForReuse {
    [super prepareForReuse];
//    [self.subscription dispose];
//    self.subscription = nil;
}

@end
